package com.mydesignpattern.beijing.factory.simpleFactory;

import com.mydesignpattern.beijing.factory.Person;
import com.mydesignpattern.beijing.factory.simpleFactory.cars.Car;
import com.mydesignpattern.beijing.factory.simpleFactory.cars.impl.OrdinaryCar;
import com.mydesignpattern.beijing.factory.simpleFactory.cars.impl.SportCar;
import com.mydesignpattern.beijing.factory.simpleFactory.cars.impl.TruckCar;

/**
 * 工厂类
 * Created by nevermore on 17/4/16.
 */
public class Factory {

    /**
     * 获取车的方法
     * 根据不同的参数类型，返回不同的车
     * @param p
     * @return
     */
    public Car getCar(Person p){
        switch (p.getWant()){
            case "ordinary":
                return new OrdinaryCar();
            case "sport":
                return new SportCar();
            case "truck":
                return new TruckCar();
            default:
                return null;
        }
    }
}

